<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<style>
    .layui-table-cell {
        height: inherit;
    }
    .layui-layer-btn1 {
        background-color: red !important;
        color: #ffffff !important;
    }
</style>
<body>
<div class="layui-fluid">
    <fieldset class="layui-elem-field">
        <legend>引流审核</legend>
        <div class="layui-field-box">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">请选择</option>
                                    <option value="0">未审核</option>
                                    <option value="1">已通过</option>
                                    <option value="2">已拒绝</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table id="demo" lay-filter="demo"></table>
                    <script type="text/html" id="money">
                        {{d.money}} 元
                    </script>
                    <script type="text/html" id="status">
                        {{# if (d.status == 0){ }}
                        待审核
                        {{# }else if(d.status == 1){ }}
                        已通过
                        {{# }else if(d.status == 2){ }}
                        已拒绝
                        {{# } }}
                    </script>
                    <script type="text/html" id="table-content-list">
                        {{# if (d.status == 0){ }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="shenhe">审核</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </fieldset>

</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table'], function(){
        var $ = layui.$,
                form = layui.form,
                table = layui.table;

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('demo', {
                url: "{:url('Gift/yin_examine')}",
                where: field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //执行渲染
        table.render({
            elem: '#demo',
            url: "{:url('Gift/yin_examine')}",
            method: 'post',
            cols: [[
                {field: 'name', title: '大礼包名称'},
                {field: 'uid', title: '引流商家'},
                {field: 'zid', title: '组合人'},
                {field: 'money', title: '礼包所需价格', templet: '#money'},
                {field: 'status', title: '礼包所需价格', templet: '#status'},
                {fixed: 'right', title: '操作', width: 250, align:'center', toolbar: '#table-content-list'}
            ]],
            page: {
                limits: [10, 20, 30, 40, 50]
            }
        });

        //监听事件
        table.on('tool(demo)', function(obj){
            var id = obj.data.id;
            var layEvent = obj.event;
            if (layEvent === 'shenhe'){
                layer.confirm('确定通过审核吗?', {
                    title:'提示',
                    offset: ['25%', '35%'],
                    area: '250px',
                    btn: ['通过', '拒绝'],
                    btnAlign: 'c'
                }, function(){
                    var index = layer.load(1, {offset: ['30%', '42%']});
                    $.post("{:url('Gift/yin_shenhe')}", {id:id,type:1}, function(e){
                        layer.close(index);
                        if (e.code == 200){
                            layer.msg(e.data, {offset: ['30%', '40%']});
                            setTimeout(function (){
                                table.reload('demo');
                            }, 500);
                        }else{
                            layer.msg(e.msg, {offset: ['30%', '40%']});
                        }
                    }, 'json');
                }, function(){
                    var index = layer.load(1, {offset: ['30%', '42%']});
                    $.post("{:url('Gift/yin_shenhe')}", {id:id,type:2}, function(e){
                        layer.close(index);
                        if (e.code == 200){
                            layer.msg(e.data, {offset: ['30%', '40%']});
                            setTimeout(function (){
                                table.reload('demo');
                            }, 500);
                        }else{
                            layer.msg(e.msg, {offset: ['30%', '40%']});
                        }
                    }, 'json');
                });
            }
        });
    });
</script>
</body>
</html>
